package com.linkage.lcims.base.dao.business.impl;

import java.util.List;

import com.linkage.lcims.base.dao.HibernateBaseDAOImpl;
import com.linkage.lcims.base.dao.business.interfaces.GroupAuthDAO;
import com.linkage.lcims.base.po.business.BdGroupAuth;
import com.linkage.util.exception.DAOException;

/**
 * @author Owner
 * @date 2008-1-7 TODO To change the template for this generated type comment go
 *       to Window - Preferences - Java - Code Style - Code Templates
 * @version 1.0
 */
public class GroupAuthDAOImpl extends HibernateBaseDAOImpl implements
		GroupAuthDAO {

	public int deleteGroupAuth(Integer groupid) throws DAOException {
		try {
			StringBuffer sql = new StringBuffer();
			sql.append("delete BD_GROUP_AUTH where groupid=").append(groupid);
			return this.deleteBySql(sql.toString());
		} catch (Exception e) {
			throw new DAOException(e, this.getClass());
		}
	}

//	public Integer getMaxPriority(Integer groupid, Integer recordid) throws DAOException {
//		
//		Session session = this.getSession();
//		Connection conn = session.connection();
//		Statement stmt=null;
//		ResultSet rest= null;
//		Integer maxPriority = new Integer(0);
//		
//		StringBuffer sql = new StringBuffer("select ISNULL(max(c.priority),0) as maxval from BD_GROUP_AUTH as c");
//		sql.append(" where groupid=").append(groupid).append(" and recordid=").append(recordid);
//		
//		try {
//			stmt = conn.createStatement();
//			rest = stmt.executeQuery(sql.toString());
//			while(rest.next()){
//				maxPriority =new Integer(rest.getInt("maxval"));
//			}
//			
//		} catch (SQLException e) {
//			e.printStackTrace();
//			throw new DAOException(e);
//		}
//		finally
//		{
//			if(rest!=null){
//				try {
//					rest.close();
//				} catch (SQLException e) {
//					e.printStackTrace();
//					throw new DAOException(e);
//				}
//			}
//			if(stmt!= null){
//				try {
//					stmt.close();
//				} catch (SQLException e) {
//					e.printStackTrace();
//					throw new DAOException(e);
//				}
//			}
////			if(conn!= null){
////				try {
////					conn.close();
////				} catch (SQLException e) {
////					e.printStackTrace();
////					throw new DAOException(e);
////				}
////			}
//		}
//		return maxPriority;
//	}
//
//	public Integer getMaxRecordid(Integer groupid) throws DAOException {
//		Session session = this.getSession();
//		Connection conn = session.connection();
//		Statement stmt=null;
//		ResultSet rest= null;
//		Integer maxRecordid = new Integer(0);
//		
//		StringBuffer sql = new StringBuffer("select ISNULL(max(c.recordid),0) as maxid from BD_GROUP_AUTH as c ");
//		sql.append("where groupid=").append(groupid);
//		
//		try {
//			stmt = conn.createStatement();
//			rest = stmt.executeQuery(sql.toString());
//			while(rest.next()){
//				maxRecordid =new Integer(rest.getInt("maxid"));
//			}
//			
//		} catch (SQLException e) {
//			e.printStackTrace();
//			throw new DAOException(e);
//		}
//		finally
//		{
//			if(rest!=null){
//				try {
//					rest.close();
//				} catch (SQLException e) {
//					e.printStackTrace();
//					throw new DAOException(e);
//				}
//			}
//			if(stmt!= null){
//				try {
//					stmt.close();
//				} catch (SQLException e) {
//					e.printStackTrace();
//					throw new DAOException(e);
//				}
//			}
//		}
//		return maxRecordid;
//	}

	public void save(BdGroupAuth groupAuth) throws DAOException {
		super.save(groupAuth);
	}

	@SuppressWarnings("unchecked")
	public List<BdGroupAuth> getRecordid(Integer groupid) throws DAOException {
		
		String hql="from BdGroupAuth where groupid="+groupid;
		List<BdGroupAuth> list=this.query(hql);
		return list;
	}

	public void deleteAuthRecord(BdGroupAuth groupAuth)
			throws DAOException {
		this.delete(BdGroupAuth.class, groupAuth.getComp_id());
		
	}
	
	public BdGroupAuth getRecord(BdGroupAuth groupAuth) throws DAOException{
		return (BdGroupAuth)this.getByID(BdGroupAuth.class, groupAuth.getComp_id());
		
	}

	@SuppressWarnings("unchecked")
	public List<BdGroupAuth> getAll() throws DAOException {
		return super.getAll(BdGroupAuth.class);
	}
	
}
